package cn.itcast.servlet;

import cn.itcast.service.CustomerService;
import cn.itcast.vo.Customer;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ListByWhereServlet
  extends HttpServlet
{
  private static final long serialVersionUID = 8574912960251367600L;
  
  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
  {
    request.setCharacterEncoding("UTF-8");
    String username = request.getParameter("username");
    String type = request.getParameter("type");
    
    request.setAttribute("username", username);
    request.setAttribute("type", type);
    
    CustomerService cs = new CustomerService();
    
    List<Customer> cList = cs.findByWhere(username, type);
    
    request.setAttribute("cList", cList);
    
    request.getRequestDispatcher("/pages/list.jsp").forward(request, response);
  }
  
  public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
  {
    doGet(request, response);
  }
}
